package leetcode.code1992;

import java.util.ArrayList;
import java.util.List;

import leetcode.IDebug;

public class Solution implements IDebug {

	int m, n;
	int[][] land;

	public int[][] findFarmland(int[][] land) {
		m = land.length;
		n = land[0].length;
		this.land = land;
		List<int[]> tmp = new ArrayList<>();
		for (int i = 0; i < m; i++) {
			for (int j = 0; j < n; j++) {
				int cur = land[i][j];
				if (cur == 1) {
					int[] farm = find(i, j);
					tmp.add(farm);
				}
			}
		}
		int[][] ans = new int[tmp.size()][4];
		for (int i = 0; i < tmp.size(); i++) {
			ans[i] = tmp.get(i);
		}
		return ans;
	}

	private int[] find(int x, int y) {
		for (int i = x; i < m; i++) {

		}
		int h = x;
		while (h < m && this.land[h][y] == 1) {
			h++;
		}
		int w = y;
		while (w < n && this.land[x][w] == 1) {
			w++;
		}
		for (int i = x; i < h; i++) {
			for (int j = y; j < w; j++) {
				this.land[i][j] = -1;
			}
		}
		return new int[] { x, y, h - 1, w - 1 };
	}

	@Override
	public void debug4() {
		// TODO Auto-generated method stub

	}

	@Override
	public void debug3() {
		// TODO Auto-generated method stub

	}

	@Override
	public void debug2() {
		// TODO Auto-generated method stub

	}

	@Override
	public void debug1() {
		// TODO Auto-generated method stub

	}

	public static void main(String[] args) {
		// TODO Auto-generated method stub

	}

}
